import { getStaffInfo } from '@/gql/earthPushing/user';
import { getStaffBanInfo } from '@/gql/earthPushing/checkWork';
import { toPublish } from '@mqtt';
import { defineStore } from 'pinia';
import { getDriverID } from '@/stores/driverID';
import { showLoading } from '@/utils/prompt';
export const useUserInformation = defineStore('userSale', {
	state: () => ({
		userInfor: {},
		delevery_id: uni.getStorageSync('delivery_id') ? uni.getStorageSync('delivery_id') : 0,
		staffBanInfo: {},
	}),
	getters: {},
	actions: {
		getUserInfo() {
			showLoading()
			const payload = {
				query: getStaffInfo,
				variables: { staff_id: getDriverID() },
			};
			toPublish(
				'ql/staff/getStaffInfo',
				payload,
				(obj : any) => {
					uni.hideLoading()
					const { getStaffInfo } = obj.data;
					this.userInfor = getStaffInfo
					uni.setStorageSync('delivery_id', getStaffInfo.delevery_id)
				},
			);
		},
		getStaffBan(num : number, type : string) {
			showLoading()
			const payload = {
				query: getStaffBanInfo,
				variables: { ban_id: num },
			};
			const topic = type ? `ql/${type}/getStaffBanInfo` : 'ql/staff/getStaffBanInfo'
			toPublish(topic,
				payload,
				(obj : any) => {
					uni.hideLoading()
					const { getStaffBanInfo } = obj.data;
					this.staffBanInfo = getStaffBanInfo
				},
			);
		}
	},
});